package com.bjpowernode.money.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bjpowernode.money.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author ZHAOZHENYU
 * @since 2022/10/18
 */
@Service(interfaceClass = RedisService.class,version = "1.0.0",timeout = 20000)
@Component
public class RedisServiceImpl implements RedisService {

    @Autowired(required = false)
    private RedisTemplate redisTemplate;

    @Override
    public void push(String phone, String yzmCode) {
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.opsForValue().set(phone,yzmCode,5, TimeUnit.MINUTES);
    }

    @Override
    public String pop(String phone) {
        return (String) redisTemplate.opsForValue().get(phone);
    }
}
